/// @tags: DP
#include <cstdio>
#include <iostream>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

typedef long long ll;

constexpr int maxn = 2e5 + 2, mod = 998244353;

int a[maxn];

ll qpow(ll base, int exp) {
  ll res = 1;
  for (; exp; exp >>= 1, base = base * base % mod)
    if (exp & 1) res = res * base % mod;
  return res;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, cnt0 = 0, cnt1 = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      cnt0 += !a[i];
    }
    for (int i = 1; i <= cnt0; ++i) {
      cnt1 += a[i];
    }
    ll binom = (ll)n * (n - 1) % mod * qpow(2, mod - 2) % mod;
    ll ans = 0;
    for (int i = 1; i <= cnt1; ++i) {
      ans += qpow((ll)i * i % mod, mod - 2) * binom % mod;
      ans %= mod;
    }
    cout << ans << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF829E Wish I Knew How to Sort.in", "r", stdin);
  freopen("CF829E Wish I Knew How to Sort.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
